package maskedpixel.ogmo.utils 
{
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author Erin M Gunn
	 */
	public final class OgmoTileSet
	{
		/**
		 * Name of this tileset.
		 */
		public var name:String;
		
		/**
		 * The embedded asset that is this tileset in flash.
		 */
		public var asset:Class;
		
		/**
		 * A string containing the location of the image file to use in Ogmo.
		 */
		public var image:String;
		
		/**
		 * the width of the tiles in this tileSet.
		 */
		public var tileWidth:uint;
		
		/**
		 * Height of the tiles in this tileSet.
		 */
		public var tileHeight:uint;
		
		/**
		 * Rows of tiles in the tileset.
		 */
		public var rows:uint;
		
		/**
		 * columns of tiles in the tileset.
		 */
		public var columns:uint;
		
		/**
		 * The location on Ogmo's drawing rectangle to place each tile in this tileSet.
		 */
		public var rectangle:Array;
		
		/**
		 * Constructor.
		 * @param	name		Name of the tileSet.
		 * @param	asset		The embedded asset that is this tileset in flash.	
		 * @param	image		A string containing the location and name of the image file to use in Ogmo.
		 * @param	tileWidth	The width of the tiles in this tileSet.
		 * @param	tileHeight	The height of the tiles in this tileSet.
		 * @param	rectangle	The location on the drawing rectangle to place each tile in this tileSet.
		 */
		public function OgmoTileSet(name:String, asset:Class, image:String, tileWidth:uint, tileHeight:uint, rows:uint, columns:uint, rectangle:Array = null) 
		{
			this.name = name;
			this.image = image;
			this.asset = asset;
			this.tileWidth = tileWidth;
			this.tileHeight = tileHeight;
			this.rows = rows;
			this.columns = columns;
			this.rectangle = rectangle;
			
			OgmoTileSet.tiles[this.name] = this;
		}
		
		/**
		 * Generates the XML representing this Tile Set in the ogmo project file.
		 * @return
		 */
		public function generateXML():XML
		{
			var xml:XML = new XML();
			xml = <tileset/>;
			xml.@name = name;
			xml.@image = image;
			xml.@tileWidth = tileWidth;
			xml.@tileHeight = tileHeight;
			if (rectangle == null || rectangle.length != 9)
			{
				rectangle = [0, 1, 2, 3, 4, 5, 6, 7, 8];
			}
			xml.rectangle.@topLeft = rectangle[0];
			xml.rectangle.@top = rectangle[1];
			xml.rectangle.@topRight = rectangle[2];
			xml.rectangle.@left = rectangle[3];
			xml.rectangle.@middle = rectangle[4];
			xml.rectangle.@right = rectangle[5];
			xml.rectangle.@bottomLeft = rectangle[6];
			xml.rectangle.@bottom = rectangle[7];
			xml.rectangle.@bottomRight = rectangle[8];
			
			return xml;
		}
		
		/**
		 * A container holding a reference of the embedded flash asset that can be retrieved by a name lookup.
		 */
		public static var tiles:Object = new Object();
	}

}